package cn.wjssl.domain.activity.service.quota.policy.impl;

import cn.wjssl.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import cn.wjssl.domain.activity.model.entity.ActivityOrderEntity;
import cn.wjssl.domain.activity.model.valobj.OrderStateVO;
import cn.wjssl.domain.activity.repository.IActivityRepository;
import cn.wjssl.domain.activity.service.quota.policy.ITradePolicy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 不需要支付的sku单, 例如通过签到等, 直接获得返利的处理器
 */
@Slf4j
@Component("rebate_no_pay_trade")
public class RebateNoPayTradePolicy implements ITradePolicy {

    @Resource
    private IActivityRepository repository;

    /**
     * 返利订单处理
     * @param createQuotaOrderAggregate
     */
    @Override
    public void trade(CreateQuotaOrderAggregate createQuotaOrderAggregate) {
        // 1. 设置订单的状态为completed, 并且设置支付的金额为0
        ActivityOrderEntity orderEntity = createQuotaOrderAggregate.getActivityOrderEntity();
        orderEntity.setState(OrderStateVO.completed);
        orderEntity.setPayAmount(BigDecimal.ZERO);
        // 2. 存入sku单
        repository.doSaveNoPayOrder(createQuotaOrderAggregate);
    }
}
